home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
misc
/
emu
/
ATUtilities.lha
/
ATUtilities
/
joy.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-09-26
|
8KB
|
384 lines
/* ******************************************************************* */
/* ** ** */
/* ** ATUtilities Joystick Manager ** */
/* ** Copright (C) 1992-1994 by Thomas Dreibholz ** */
/* ** All rights reserved ** */
/* ** ** */
/* ******************************************************************* */
#include "janus.h"
#include "ATUtilities.h"
#define XOR(a,b) ((a || b) && !(a && b))
#define BIT0 (1<<0)
#define BIT1 (1<<1)
#define BIT4 (1<<4)
#define BIT5 (1<<5)
#define BIT6 (1<<6)
#define BIT7 (1<<7)
#define BIT8 (1<<8)
#define BIT9 (1<<9)
UBYTE *JoyPort="ATUtilities Joystick-Manager";
UBYTE *PrefsName="AT:Prefs/JoystickManager.prefs";
UBYTE *HelpName="AT:Help/JoystickManager.help";
struct JoyPrefs
{
UBYTE JoystickB;
UBYTE Fire12;
};
struct JoyPrefs JoyPrefs={1,1};
struct JanusBase *JanusBase;
struct Library *GfxBase;
struct Library *IntuitionBase;
struct Library *ATUtilitiesBase;
struct AppManager *app;
struct Message *AppMessage;
struct ExtSetupSig *ExtSetupSig;
struct Window *WindowPtr;
struct RastPort *rp;
struct CommMemory *jhbyte,*jhword;
LONG JanusSignal;
LONG PortSignal;
ULONG JanusSignalMask;
ULONG PortSignalMask;
ULONG AppSignalMask;
ULONG WaitSignalMask;
ULONG Signale;
WORD jx,jy;
VOID HandleInt();
VOID ShowInfo();
VOID OpenAll();
VOID CloseAll();
BOOL EinstellungenAendern();
UWORD GetJoystick();
UBYTE GetCIA();
struct MsgPort *Port;
/* Installationsroutine */
VOID main()
{
REGISTER UWORD i;
REGISTER BOOL bool;
OpenAll();
bool=FALSE;
jx=180;
jy=120;
while(bool==FALSE)
{
Signale=Wait(WaitSignalMask);
if(Signale & PortSignalMask)
{
i=Received(Port);
switch(i)
{
case UTILITY_CALL:
bool=EinstellungenAendern();
break;
case UTILITY_QUIT:
bool=ExitWarning();
break;
case UTILITY_INFO:
ShowInfo();
break;
case UTILITY_HELP:
Help(HelpName,0);
break;
}
}
if(Signale & JanusSignalMask)
{
HandleInt();
}
if(app!=NULL)
{
if(Signale & AppSignalMask)
{
AppMessage=GetMsg(app->Port);
if(AppMessage!=NULL)
{
ReplyMsg(AppMessage);
bool=EinstellungenAendern();
}
}
}
}
CloseAll();
}
#asm
public _GetJoystick
_GetJoystick:
clr.l d0
move.w $dff00c,d0
rts
public _GetCIA
_GetCIA:
clr.l d0
move.b $bfe001,d0
rts
#endasm
/* PC-Befehle ausführen */
VOID HandleInt()
{
REGISTER UWORD joydat;
REGISTER ULONG mem;
REGISTER UWORD i,j;
REGISTER UWORD cia;
switch(jhword->Arg1)
{
case 1:
joydat=GetJoystick();
if(joydat & BIT1)
{
jx+=60;
if(jx>360) jx=360;
}
if(joydat & BIT9)
{
jx-=60;
if(jx<0) jx=0;
}
if(XOR((joydat & BIT8),(joydat & BIT9)))
{
jy-=60;
if(jy<0) jy=0;
}
if(XOR((joydat & BIT0),(joydat & BIT1)))
{
jy+=60;
if(jy>240) jy=240;
}
if(JoyPrefs.JoystickB)
{
jhword->Arg4=jx;
jhword->Arg5=jy;
}
else
{
jhword->Arg2=jx;
jhword->Arg3=jy;
}
break;
case 2:
cia=GetCIA();
if(!(cia & BIT7))
{
if(JoyPrefs.JoystickB)
{
if(JoyPrefs.Fire12)
jhword->Arg2 &= (0xffff-BIT7-BIT6);
else
jhword->Arg2 &= (0xffff-BIT6);
}
else
{
if(JoyPrefs.Fire12)
jhword->Arg2 &= (0xffff-BIT4-BIT5);
else
jhword->Arg2 &= (0xffff-BIT4);
}
}
break;
case 3:
jx=180;
jy=120;
break;
}
SendJanusInt(28);
}
/* Installationsroutine */
VOID OpenAll()
{
REGISTER UWORD i;
register struct MsgPort *p;
register struct FileHandle *fh;
ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
if(ATUtilitiesBase==NULL)
{
printf("FEHLER: Kann ATUtilities-Library nicht öffnen.\n");
CloseAll();
}
GfxBase=OpenLibrary("graphics.library",0L);
IntuitionBase=OpenLibrary("intuition.library",0L);
if((GfxBase==NULL)||(IntuitionBase==NULL))
{
CloseAll();
}
p=FindPort(JoyPort);
if(p!=NULL)
{
InfoRequest("ATUtilities Joystick-Handler ist schon aktiv.");
CloseAll();
}
JanusBase=OpenLibrary("janus.library",0L);
if(JanusBase==NULL)
{
ErrorRequest(ERROR_JANUS);
CloseAll();
}
Port=CreatePort(JoyPort,0L);
if(Port==NULL)
{
ErrorRequest(ERROR_MPORT);
CloseAll();
}
fh=Open(PrefsName,MODE_OLDFILE);
if(fh!=NULL)
{
Read(fh,&JoyPrefs,sizeof(struct JoyPrefs));
Close(fh);
}
ExtSetupSig=CreatePublicHandler(28);
if(ExtSetupSig==NULL)
{
CloseAll();
}
app=CreateAppItem("ATUtilities Joystick-Manager");
if(app!=NULL) AppSignalMask=app->SignalMask; else AppSignalMask=0;
jhword=ExtSetupSig->WordAccess;
jhbyte=ExtSetupSig->ByteAccess;
PortSignal=Port->mp_SigBit;
PortSignalMask=(1L<<PortSignal);
JanusSignal=ExtSetupSig->JanusSignal;
JanusSignalMask=ExtSetupSig->JanusSignalMask;
WaitSignalMask=PortSignalMask+JanusSignalMask+AppSignalMask;
ChangeTaskPri(10);
}
/* Programmende */
VOID CloseAll()
{
if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
if(Port) DeletePort(Port);
if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
if(GfxBase) CloseLibrary(GfxBase);
if(IntuitionBase) CloseLibrary(IntuitionBase);
if(JanusBase) CloseLibrary(JanusBase);
exit(0);
}
/* Einstellungsfenster */
BOOL EinstellungenAendern()
{
REGISTER BOOL bool,ende;
REGISTER ULONG Class;
register struct Window *win;
register struct Gadget *t1,*t2,*gad;
register struct IntuiMessage *msg;
register struct FileHandle *fh;
register struct RastPort *rp;
register struct TextFont *opal;
UBYTE *tex1="Emuliere Joystick als PC-Joystick in Port B";
UBYTE *tex2="Sende immer beide Feuertasten";
bool=FALSE;
win=CreateStdWindow("ATUtilities - Joystick-Manager Einstellungen",
75,75,450,57+BorderHeight(),GADGETUP|CLOSEWINDOW,
WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE|GIMMEZEROZERO);
if(win!=NULL)
{
rp=win->RPort;
opal=GetOpalFont();
SetFont(rp,opal);
CreateBoolGadget(win,10,5,155,12,"Einstellungen okay",1);
CreateBoolGadget(win,170,5,155,12,"Programm beenden",2);
CreateBoolGadget(win,335,5,50,12,"Info",3);
CreateBoolGadget(win,390,5,50,12,"Hilfe",4);
if(JoyPrefs.JoystickB)
t1=CreateSToggleGadget(win,10,25,430,12,tex1,10);
else
t1=CreateNToggleGadget(win,10,25,430,12,tex1,10);
if(JoyPrefs.Fire12)
t2=CreateSToggleGadget(win,10,40,430,12,tex2,20);
else
t2=CreateNToggleGadget(win,10,40,430,12,tex2,20);
ende=FALSE;
while(ende==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
gad=msg->IAddress;
Class=msg->Class;
ReplyMsg(msg);
switch(Class)
{
case CLOSEWINDOW:
ende=TRUE;
break;
case GADGETUP:
switch(gad->GadgetID)
{
case 1:
if(t1->Flags & SELECTED) JoyPrefs.JoystickB=1; else JoyPrefs.JoystickB=0;
if(t2->Flags & SELECTED) JoyPrefs.Fire12=1; else JoyPrefs.Fire12=0;
ende=TRUE;
break;
case 2:
ende=TRUE; bool=TRUE;
break;
case 3:
ShowInfo();
break;
case 4:
Help(HelpName,0);
break;
}
break;
}
}
DeleteStdWindow(win);
if(bool==TRUE)
{
fh=Open(PrefsName,MODE_NEWFILE);
if(fh!=NULL)
{
Write(fh,&JoyPrefs,sizeof(struct JoyPrefs));
Close(fh);
}
}
}
if(bool==TRUE) bool=ExitWarning();
return(bool);
}
/* Information */
VOID ShowInfo()
{
InformationBox("ATUtilities Joystick-Manager - Information",
"$VER: Joystick-Manager - Version 4.0",
"Copyright (C) 1992-1994 by",
"Thomas Dreibholz",
"All rights reserved.",
"AT:Icons/Utility");
}